package cn.jdx.tools.zip;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;

import java.io.File;

public class JdxZipFile {
    public static void zipFile(String inputPath,String outputPath) {
        ZipParameters parameters = new ZipParameters();
        // 压缩方式
        parameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
        // 压缩级别
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
        // 要打包的文件夹
        File currentFile = new File(inputPath);
        // 生成的压缩文件
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(outputPath);
            // 遍历test文件夹下所有的文件、文件夹
            File[] fs = currentFile.listFiles();
            for (File f : fs) {
                if (f.isDirectory()) {
                    zipFile.addFolder(f.getPath(), parameters);
                } else {
                    zipFile.addFile(f, parameters);
                }
            }
        } catch (ZipException e) {
            System.err.println("[JdxZipFile.zipFile]:"+e);
        }

    }
}
